<?php


    class sthook extends stthemehook {

        public function hookCustom() { 
            //overide hook manage
//        $method = array($this, 'load_custom_wp_admin_scripts');
//        add_action('admin_enqueue_scripts', $method);
//        $method = array($this, 'customFieldCreate');
//        add_action('admin_menu', $method);
//        $method = array($this, 'customFieldHandle');
//        add_action('edit_post', $method);
            
        add_action('edit_user_profile', array($this, 'add_extra_profile_fields'));
        add_action('profile_update', array($this, 'profile_update_fields'));

        }

        
    function add_extra_profile_fields() {   
        // add extra profile fields to user edit page
        $_status = get_user_meta($_GET['user_id'], 'client_status');     
        ?>
      
        <table class="form-table">
            <tbody><tr>
                    <th><label for="description">Status</label></th>
                    <td class="profile_avatar">
                        <select name="client_status">
                            <option value="working"  selected >Working on</option>
                            <option value="finish" <?php echo $_status[0] == 'finish' ? 'selected' : '' ?> >Finish</option>
                        </select>
                    </td>
                </tr>
            </tbody></table>

        <?php
    }

    function profile_update_fields() { 
        update_user_meta($_POST['user_id'], 'client_status', $_POST['client_status']); 
    }
    
        public function customFieldCreate() {
            if (function_exists('add_meta_box')) {
                $controllerName = $this->config['theme_name'] . "Controller";
                $controllerObject = new $controllerName($this->config);
                $controllerObject->actionName = 'addPrice';
                $method = array($controllerObject, 'getAction');
                add_meta_box('custom_field', 'Produktpris', $method, 'page', 'normal');
            }
        }

        public function customFieldHandle() {
            if (isset($_POST['post_ID']))
                $pID = $_POST['post_ID'];
            if (isset($_POST['action']) && $_POST['action'] == 'editpost') {
//            if (isset($_POST['content_type'])) {
                $upload_data = wp_upload_dir();
                $img_data = array();
                foreach ($_POST['image_product'] as $row) {
                    $img_data[] = $upload_data['url'] . '/' . basename($row);
                }

                $pdf_data = array();
                foreach ($_POST['pdf_product'] as $row) {
                    if ($row != '')
                        $pdf_data[] = $upload_data['url'] . '/' . basename($row);
                    else
                        $pdf_data[] = '';
                }

                update_post_meta($pID, 'the_text', serialize($_POST['the_text']));
                update_post_meta($pID, 'the_name', serialize($_POST['the_name']));
                update_post_meta($pID, 'the_link', serialize($_POST['the_link']));
                update_post_meta($pID, 'album_id', serialize($_POST['album_id']));
                update_post_meta($pID, 'image_product', $img_data);
                update_post_meta($pID, 'pdf_product', $pdf_data);
                update_post_meta($pID, 'content_type', serialize($_POST['content_type']));

//            }
            }
        }

        public function load_custom_wp_admin_scripts() {
//        wp_register_style('custom_wp_admin_css', get_bloginfo('template_directory') . '/admin-functions/css/admin-style.css', false, '1.0.0');
//        wp_enqueue_style('custom_wp_admin_css');

            wp_register_script('ajaxupload_admin_script', get_bloginfo('template_directory') . '/admin-functions/scripts/ajaxupload.js', false, '1.0.0');
            wp_enqueue_script('ajaxupload_admin_script');
//        wp_register_script('custom_wp_admin_script', get_bloginfo('template_directory') . '/admin-functions/scripts/admin-script.js', false, '1.0.0');
//        wp_enqueue_script('custom_wp_admin_script');
            wp_register_script('sttheme_admin_script', get_bloginfo('template_directory') . '/admin-functions/scripts/sttheme.js', false, '1.0.0');
            wp_enqueue_script('sttheme_admin_script');
        }

        function widgetsInit() {
            unregister_widget('WP_Widget_Archives');
            unregister_widget('WP_Widget_Calendar');
            unregister_widget('WP_Widget_Categories');
            unregister_widget('WP_Widget_Links');
            unregister_widget('WP_Widget_Meta');
            unregister_widget('WP_Widget_Pages');
            unregister_widget('WP_Widget_Recent_Comments');
            unregister_widget('WP_Widget_Recent_Posts');
            unregister_widget('WP_Widget_RSS');
            unregister_widget('WP_Widget_Search');
            unregister_widget('WP_Widget_Tag_Cloud');
            unregister_widget('WP_Widget_Text');
            unregister_widget('WP_Nav_Menu_Widget');
// 
            register_sidebar(array(
                'name' => __('Home Left Area', $this->config['theme_name']),
                'id' => 'home_left_area',
                'description' => __('Home Left Area', $this->config['theme_name']),
                'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
                'after_widget' => '</div>',
                'before_title' => '<h3 class="widget-title">',
                'after_title' => '</h3>',
            ));
//      
            register_sidebar(array(
                'name' => __('Page/post sidebar', $this->config['theme_name']),
                'id' => 'page_sidebar',
                'description' => __('', $this->config['theme_name']),
                'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
                'after_widget' => '</div>',
                'before_title' => '<h3 class="widget-title">',
                'after_title' => '</h3>',
            ));
            register_sidebar(array(
                'name' => __('Right sidebar', $this->config['theme_name']),
                'id' => 'right_sidebar',
                'description' => __('Right sidebar', $this->config['theme_name']),
                'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
                'after_widget' => '</div>',
                'before_title' => '<h3 class="widget-title">',
                'after_title' => '</h3>',
            ));
        }

    }

